<?php

// no direct access
defined('_JEXEC') or die;
$class = ' class="first"';
?>
<link rel="stylesheet" href="<?php echo JURI::base(); ?>css/myAccount.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="<?php echo JURI::base(); ?>js/multiselect/jquery-ui.css" />
<link type="text/css" href="<?php echo JURI::base(); ?>css/buttons.css" rel="stylesheet" />
<script type="text/javascript" src="<?php echo JURI::base(); ?>js/dialog/jquery-ui-1.8.20.custom.min.js"></script>

<?php
if (count($this->items) > 0) :
?>
<script type="text/javascript">
    jQuery(function(){
        // Dialog
        jQuery('#dialog').dialog({
            autoOpen: false,
            width: 500,
            height: 380,
            open: function(){
                jQuery(".dialog-content").html("");
                var queryString = 'id='+jQuery("#promotion-link").val();
                jQuery.ajax({
                    type: "POST",
                    url: "index.php?option=com_promotions&layout=details&view=promotions",
                    data: queryString,
                }).success(function( html ) {
                    jQuery(".dialog-content").html(html);
                    jQuery(this).dialog("open");
                });
                
            },
            buttons: {
                "Close": function() {
                    jQuery(this).dialog("close");
                }
            }
        });
            
        jQuery('.promotion-list').click(function(index){
            jQuery("#promotion-link").val(jQuery(this).attr("name"));
            jQuery('#dialog').dialog('open');
            return false;               
        });    
    });
    
    
</script>
<ul class="list-promotions">
<?php 
    foreach($this->items as $id => $item) : 
        $images = json_decode($item->params);
        if(!empty($images)):
            $images = '<img alt="'.$item->name.'" title="'.$item->name.'" src="'.$images->imageurl_1.'" />';
        else:
            $images = '';
        endif;
        echo '
            <li>
                <div class="category-desc">
                    <a href="javascript:void(0)" class="promotion-list" name="'.$item->id.'">'.$images.'</a>
                </div>          
            </li>    
        ';
    endforeach;
?>
</ul>
<input type="hidden" id="promotion-link" value="" />
<?php endif; ?>
<!-- ui-dialog -->
<div id="dialog" title="Promotion details">
    <div class="dialog-content">
        
    </div>
</div>